package com.freemarker.db;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.freemarker.vo.SamplePO;

public class SpringUtil {

	public static String[] fileName = { "data_config_mysql.xml" };

	public static void main(String[] args) {

		SamplePO taskInfo = (SamplePO) SpringUtil.getObject("po");
		System.out.println(taskInfo.toString());
	}

	
	public static Object getObject(String id) {
		Object object = null;
		ApplicationContext context = new ClassPathXmlApplicationContext(fileName);
		object = context.getBean(id);
		return object;
	}

	public static SamplePO getSamplePO(String id) {
		Object object = null;
		ApplicationContext context = new ClassPathXmlApplicationContext(fileName);
		object = context.getBean(id);
		return (SamplePO) object;
	}

	public static String getData(String id) {
		ApplicationContext context = new ClassPathXmlApplicationContext(fileName);
		SamplePO samplePO = (SamplePO) context.getBean(id);

		return samplePO.getData().trim();
	}
	
	public static ApplicationContext getXmlName(String fileName) {
		ApplicationContext context = new ClassPathXmlApplicationContext(fileName);
		return context;
	}
}
